<?php

class Countries_model extends CI_Model{
	
	public function __construct(){
		parent::__construct();
	}
	
	function create(){
		$data = array(
					'name' => $this->input->post('name'),
					'iso_code_2' =>  $this->input->post('iso_code_2'),
					'iso_code_3' => $this->input->post('iso_code_3'),
					'address_format' => $this->input->post('address_format'),
					'postcode_required' => $this->input->post('postcode_required'),
					'status' => $this->input->post('status')
				);
		$this->db_front->insert('country', $data);	
	}
	
	function getAll($page='', $limit=''){
		if(!empty($limit))
		$this->db_front->limit($limit,$page);
		
		$query = $this->db_front->get('country');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}	
	}
	
	function update($country_id){
		$data = array(
					'name' => $this->input->post('name'),
					'iso_code_2' =>  $this->input->post('iso_code_2'),
					'iso_code_3' => $this->input->post('iso_code_3'),
					'address_format' => $this->input->post('address_format'),
					'postcode_required' => $this->input->post('postcode_required'),
					'status' => $this->input->post('status')
				);
        $this->db_front->where('country_id', $country_id);
        $this->db_front->update('country', $data);
	}
	
	function select($country_id){
        return $this->db_front->get_where('country', array('country_id'=>$country_id))->row();
    }
	
	function delete($country_id){
		$this->db_front->delete('country', array('country_id'=>$country_id));
	}
	
	function getStatus($country){
		$query = $this->db->query('select status from country where country_id = "'.$country.'"');
		if($query -> num_rows() > 0){
			foreach ($query -> result() as $rows){
				$data[] = $rows;	
			}	
			return $data;
		}
	}
	
}

?>